package com.yan.lesson01;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

//还是要等待客户端的连接
public class UDPServerDome01 {
    public static void main(String[] args) throws IOException {
        //开放端口
        DatagramSocket socket = new DatagramSocket(9090);
        //接收数据包
        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);
        //接收包
        socket.receive(packet);
        System.out.println(packet.getAddress().getHostAddress()+"说："+new String(packet.getData(),0,packet.getLength()));
        //关闭流
        socket.close();
    }
}
